package com.example.demo.login.controller;

import com.example.demo.login.entity.User;
import com.example.demo.login.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@CrossOrigin("http://localhost:8000")
public class RegistController {
    @Autowired
    private UserService userService;

    @RequestMapping("/regist")
    @ResponseBody
    private HashMap<String, Object> regist(@RequestBody User user) {
        HashMap<String,Object> map = new HashMap();
        try{
            User user2 = userService.queryByName2(user);
            if(user2 == null) {
                userService.regist(user);
                map.put("result","success");
                map.put("message","注册成功");
                map.put("data",user);
            }else {
                map.put("result","error");
                map.put("message","注册失败");
            }
        }catch (Exception e){
            map.put("message","注册失败");
            map.put("result","error");
        }
        return map;
    }
}
